package sctu.edu.java.year2016.team01.xuhanmei.day20160521.chapter5_3;

/**
 * Created by Administrator on 2016/5/24.
 * 编写一个二维数组，将其元素的和输出
 */
public class Sum2 {
    public static void main(String[] args) {
        int sum = 0;
        int[][] arr = new int[][]{{1, 2, 3, 4, 4}, {2, 3, 2, 34, 33}, {11, 22, 33, 44, 55}, {66, 77, 88, 99, 12},
                {13, 14, 15, 16, 17}};
        System.out.println("二维数组里的元素有：");


        for (int i = 0; i < arr.length; i++) {              //遍历
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");

            }
        }


        for (int a = 0; a < arr.length; a++) {
            for (int b = 0; b < arr[a].length; b++) {
                sum = sum + arr[a][b];
            }
        }
        System.out.println("\n这个二维数组的元素之和是：" + sum + "\n");
    }
}
